package start.spring.basic.demo.controller.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import start.spring.basic.demo.common.DemoConstant;
import start.spring.basic.demo.controller.BaseController;
import start.spring.basic.demo.entity.TestH;
import start.spring.basic.demo.service.demo.IH2DemoService;
import start.spring.basic.log.ServiceLog;
import start.spring.basic.page.PageQuery;
import start.spring.basic.response.ResponseData;
import start.spring.basic.response.ResponsePage;

@RestController
@RequestMapping("/h2")
@Api(tags = "h2使用demo相关接口")
public class H2DemoController extends BaseController {

	@Autowired
	IH2DemoService h2DemoService;
	
	@ServiceLog(businessType = "测试h2保存数据", systemType = DemoConstant.SYSTEM_TYPE, recordResult = true, userId = "")
	@RequestMapping(value = "/mp/add", method = {RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value = "保存数据", notes = "测试mybatis plus下h2数据库保存数据")
	public ResponseData<String> mpAdd() {
		return h2DemoService.mpAdd();
	}
	
	@ServiceLog(businessType = "测试h2分页查询", systemType = DemoConstant.SYSTEM_TYPE, recordResult = false, userId = "")
	@RequestMapping(value = "/mp/multidb/query/page", method = {RequestMethod.GET})
	@ResponseBody
	@ApiOperation(value = "测试h2分页查询", notes = "测试mybatis plus下分页查询")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "a", value = "测试字段a", dataType = "String", required = false)
	})
	public ResponsePage<TestH> mpMultiDbQueryPage(PageQuery pageQuery,
			@RequestParam(required = false) String a) {
		return super.returnResponse(h2DemoService.mpMultiDbQueryPage(pageQuery,a));
	}
	
	@ServiceLog(businessType = "测试h2删除数据", systemType = DemoConstant.SYSTEM_TYPE, recordResult = true, userId = "")
	@RequestMapping(value = "/mp/del", method = {RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value = "删除数据", notes = "测试mybatis plus下h2数据库删除数据")
	public ResponseData<String> mpDel() {
		return h2DemoService.mpDel();
	}
}
